<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>README - rubyXL 3.4.35</title>


  <meta name="keywords" content="ruby,documentation,README">
  <meta name="description" content="README: badge. fury.">




<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
</script>

<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="file">
<div id="navigation-toggle" role="button" tabindex="0" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
  <span aria-hidden="true">&#9776;</span>
</div>


<nav id="navigation" role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  
<div class="nav-section">
  <h3>Table of Contents</h3>





  <ul class="link-list" role="directory">
    




          <li>
            <details open>
              <summary>
      <a href="#label-rubyXL">rubyXL</a>
</summary>
              <ul class="link-list" role="directory">
                




          <li>
      <a href="#label-To+Install-3A">To Install:</a>
</li>




          <li>
            <details open>
              <summary>
      <a href="#label-To+Use-3A">To Use:</a>
</summary>
              <ul class="link-list" role="directory">
                




          <li>
      <a href="#label-Convenience+methods">Convenience methods</a>
</li>




          <li>
      <a href="#label-Parsing+an+existing+workbook">Parsing an existing workbook</a>
</li>




          <li>
      <a href="#label-Creating+a+new+Workbook">Creating a new Workbook</a>
</li>




          <li>
            <details open>
              <summary>
      <a href="#label-Accessing">Accessing</a>
</summary>
              <ul class="link-list" role="directory">
                




          <li>
      <a href="#label-Accessing+a+Worksheet">Accessing a Worksheet</a>
</li>




          <li>
      <a href="#label-Accessing+a+Row+-28Array+of+Cells-29">Accessing a Row (Array of Cells)</a>
</li>




          <li>
      <a href="#label-Accessing+a+Cell+object">Accessing a Cell object</a>
</li>




          <li>
      <a href="#label-Wrappers+for+accessing+Cell+properties">Wrappers for accessing Cell properties</a>
</li>




          <li>
      <a href="#label-Wrappers+for+accessing+Row+properties+">Wrappers for accessing Row properties </a>
</li>




          <li>
      <a href="#label-Accessing+column+properties">Accessing column properties</a>
</li>



              </ul>
            </details>
          </li>




          <li>
            <details open>
              <summary>
      <a href="#label-Modifying">Modifying</a>
</summary>
              <ul class="link-list" role="directory">
                




          <li>
      <a href="#label-Adding+Worksheets">Adding Worksheets</a>
</li>




          <li>
      <a href="#label-Renaming+Worksheets">Renaming Worksheets</a>
</li>




          <li>
      <a href="#label-Adding+Cells">Adding Cells</a>
</li>




          <li>
      <a href="#label-Changing+Cells">Changing Cells</a>
</li>




          <li>
      <a href="#label-Changing+Fonts">Changing Fonts</a>
</li>




          <li>
      <a href="#label-Changing+Fills+++++">Changing Fills     </a>
</li>




          <li>
      <a href="#label-Changing+Borders">Changing Borders</a>
</li>




          <li>
            <details open>
              <summary>
      <a href="#label-Changing+Alignment">Changing Alignment</a>
</summary>
              <ul class="link-list" role="directory">
                




          <li>
      <a href="#label-Horizontal">Horizontal</a>
</li>




          <li>
      <a href="#label-Vertical">Vertical</a>
</li>




          <li>
      <a href="#label-Rotation">Rotation</a>
</li>



              </ul>
            </details>
          </li>




          <li>
      <a href="#label-Changing+Row+Height">Changing Row Height</a>
</li>




          <li>
      <a href="#label-Changing+Column+Width">Changing Column Width</a>
</li>




          <li>
      <a href="#label-Merging+Cells">Merging Cells</a>
</li>




          <li>
      <a href="#label-Insert+Row">Insert Row</a>
</li>




          <li>
      <a href="#label-Insert+Column">Insert Column</a>
</li>




          <li>
      <a href="#label-Delete+Row">Delete Row</a>
</li>




          <li>
      <a href="#label-Delete+Column">Delete Column</a>
</li>




          <li>
      <a href="#label-Insert+Cell">Insert Cell</a>
</li>




          <li>
      <a href="#label-Delete+Cell">Delete Cell</a>
</li>




          <li>
      <a href="#label-Modifying+Cell+Format">Modifying Cell Format</a>
</li>




          <li>
      <a href="#label-Add+hyperlink+to+a+Cell">Add hyperlink to a Cell</a>
</li>



              </ul>
            </details>
          </li>



              </ul>
            </details>
          </li>




          <li>
      <a href="#label-I-2FO">I/O</a>
</li>




          <li>
            <details open>
              <summary>
      <a href="#label-Miscellaneous">Miscellaneous</a>
</summary>
              <ul class="link-list" role="directory">
                




          <li>
      <a href="#label-Suppress+warnings+about+malformed+input+files">Suppress warnings about malformed input files</a>
</li>



              </ul>
            </details>
          </li>




          <li>
      <a href="#label-Data+validation+-28colloquially+referred+to+as+-22dropdown+list-22-29">Data validation (colloquially referred to as “dropdown list”)</a>
</li>




          <li>
      <a href="#label-For+more+information">For more information</a>
</li>




          <li>
      <a href="#label-Contributing+to+rubyXL">Contributing to rubyXL</a>
</li>




          <li>
      <a href="#label-Copyright">Copyright</a>
</li>



              </ul>
            </details>
          </li>



  </ul>
</div>


  




<div id="fileindex-section" class="nav-section">
  <h3>Pages</h3>

  <ul class="link-list">



    <li><a href="./README_rdoc.html">README</a></li>

  </ul>
</div>



  <footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a></p>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.15.1.</p>
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>
</footer>

</nav>

<main role="main" aria-label="Page README.rdoc">

<h1 id="label-rubyXL">rubyXL<span><a href="#label-rubyXL">&para;</a> <a href="#top">&uarr;</a></span></h1>

<p><a href="http://badge.fury.io/rb/rubyXL"><img src="https://badge.fury.io/rb/rubyXL.svg"></a> <a href="https://circleci.com/gh/weshatheleopard/rubyXL"><img src="https://circleci.com/gh/weshatheleopard/rubyXL.svg?style=svg"></a></p>

<p>This gem supports operating on <code>xlsx</code> files (Open XML format). While it is capable of properly parsing the entire OOXML structure, its current main emphasis is on reading files produced by MS Excel, making minor modifications to them and saving them to be opened again, while preserving as much of the structure as possible.</p>

<p>Please note that proprietary binary <code>xls</code> format is <strong>not</strong> supported by this gem. If you need to parse those files, try <a href="https://github.com/zdavatz/spreadsheet">spreadsheet</a> gem.</p>

<h2 id="label-To+Install-3A">To Install:<span><a href="#label-To+Install-3A">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">gem</span> <span class="ruby-identifier">install</span> <span class="ruby-identifier">rubyXL</span>
</pre>

<h2 id="label-To+Use-3A">To Use:<span><a href="#label-To+Use-3A">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL&#39;</span> <span class="ruby-comment"># Assuming rubygems is already required</span>
</pre>

<h3 id="label-Convenience+methods">Convenience methods<span><a href="#label-Convenience+methods">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Starting with version 3.4.0, the main data structure has been separated from the convenience methods that provide access to individual features of the <code>xlsx</code> format, in order to decrease the memory footprint. If you intend to use these features, you will need to additionally include the respective files:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL/convenience_methods/cell&#39;</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL/convenience_methods/color&#39;</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL/convenience_methods/font&#39;</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL/convenience_methods/workbook&#39;</span>
<span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL/convenience_methods/worksheet&#39;</span>
</pre>

<p>If you do not care about your RAM usage, just include them all at once by adding the following line to your code so it can continue operating just as before:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;rubyXL/convenience_methods&#39;</span>
</pre>

<h3 id="label-Parsing+an+existing+workbook">Parsing an existing workbook<span><a href="#label-Parsing+an+existing+workbook">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">workbook</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;path/to/Excel/file.xlsx&quot;</span>)
</pre>

<h3 id="label-Creating+a+new+Workbook">Creating a new Workbook<span><a href="#label-Creating+a+new+Workbook">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">workbook</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Workbook</span>.<span class="ruby-identifier">new</span>
</pre>

<h3 id="label-Accessing">Accessing<span><a href="#label-Accessing">&para;</a> <a href="#top">&uarr;</a></span></h3>

<h4 id="label-Accessing+a+Worksheet">Accessing a Worksheet<span><a href="#label-Accessing+a+Worksheet">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">workbook</span>.<span class="ruby-identifier">worksheets</span>[<span class="ruby-value">0</span>] <span class="ruby-comment"># Returns first worksheet</span>
<span class="ruby-identifier">workbook</span>[<span class="ruby-value">0</span>]            <span class="ruby-comment"># Returns first worksheet</span>
<span class="ruby-identifier">workbook</span>[<span class="ruby-string">&#39;Sheet1&#39;</span>]     <span class="ruby-comment"># Finds and returns worksheet titled &quot;Sheet1&quot;. Note that sheet names in Excel are limited to 31 character.</span>
</pre>

<h4 id="label-Accessing+a+Row+-28Array+of+Cells-29">Accessing a Row (Array of Cells)<span><a href="#label-Accessing+a+Row+-28Array+of+Cells-29">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Please note that worksheet is a <em>sparse</em> array of rows. Your code <strong>must</strong> expect that any row it plucks from the array may be <code>nil</code>.</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span> = <span class="ruby-identifier">workbook</span>[<span class="ruby-value">0</span>]
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>] <span class="ruby-comment"># Returns first row of the worksheet</span>
<span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>]            <span class="ruby-comment"># Returns first row of the worksheet</span>
</pre>

<h4 id="label-Accessing+a+Cell+object">Accessing a Cell object<span><a href="#label-Accessing+a+Cell+object">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Please note that row is a <em>sparse</em> array of cells. Your code <strong>must</strong> expect that any cell it plucks from the array may be <code>nil</code>.</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span> = <span class="ruby-identifier">workbook</span>[<span class="ruby-value">0</span>]
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>] <span class="ruby-comment"># Returns cell A1 in the worksheet</span>
<span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>]            <span class="ruby-comment"># Returns cell A1 in the worksheet</span>

<span class="ruby-identifier">cell</span> = <span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>]
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">value</span>                 <span class="ruby-comment"># Returns a properly converted value in the cell (if the file claims that the cell</span>
                           <span class="ruby-comment"># is holding a number, returns a respective Integer or Float, and so on).</span>
</pre>

<p>Or, if you prefer Excel-style references (single-cell only!)</p>

<pre class="ruby"><span class="ruby-identifier">cell</span> = <span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">cell_at</span>(<span class="ruby-string">&#39;B11&#39;</span>)
</pre>

<h4 id="label-Wrappers+for+accessing+Cell+properties">Wrappers for accessing Cell properties<span><a href="#label-Wrappers+for+accessing+Cell+properties">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">cell</span> = <span class="ruby-identifier">workbook</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>][<span class="ruby-value">0</span>]
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">is_struckthrough</span>  <span class="ruby-comment"># Returns +true+ if the cell is struckthrough, other boolean properties have same syntax</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">font_name</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">font_size</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">font_color</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">fill_color</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">horizontal_alignment</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">vertical_alignment</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">get_border</span>(<span class="ruby-value">:top</span>)
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">get_border_color</span>(<span class="ruby-value">:top</span>)
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">text_rotation</span>
</pre>

<h4 id="label-Wrappers+for+accessing+Row+properties+">Wrappers for accessing Row properties <span><a href="#label-Wrappers+for+accessing+Row+properties+">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Please note: these methods are being phased out in favor of the OOXML object model.</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span> = <span class="ruby-identifier">workbook</span>[<span class="ruby-value">0</span>]
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_fill</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_font_name</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_font_size</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_font_color</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">is_row_underlined</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_height</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-keyword">false</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_border</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:right</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_row_border_color</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:right</span>)
</pre>

<h4 id="label-Accessing+column+properties">Accessing column properties<span><a href="#label-Accessing+column+properties">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Please note: these methods are being phased out in favor of the OOXML object model.</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span> = <span class="ruby-identifier">workbook</span>[<span class="ruby-value">0</span>]
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_fill</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_font_name</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_font_size</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_font_color</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">is_column_underlined</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_width</span>(<span class="ruby-value">0</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:horizontal</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:vertical</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_border</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:right</span>)
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">get_column_border_color</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:right</span>)
</pre>

<h3 id="label-Modifying">Modifying<span><a href="#label-Modifying">&para;</a> <a href="#top">&uarr;</a></span></h3>

<h4 id="label-Adding+Worksheets">Adding Worksheets<span><a href="#label-Adding+Worksheets">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span> = <span class="ruby-identifier">workbook</span>.<span class="ruby-identifier">add_worksheet</span>(<span class="ruby-string">&#39;Sheet2&#39;</span>)
</pre>

<h4 id="label-Renaming+Worksheets">Renaming Worksheets<span><a href="#label-Renaming+Worksheets">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_name</span> = <span class="ruby-string">&#39;Cool New Name&#39;</span> <span class="ruby-comment"># Note that sheet name is limited to 31 characters by Excel.</span>
</pre>

<h4 id="label-Adding+Cells">Adding Cells<span><a href="#label-Adding+Cells">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">add_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-string">&#39;A1&#39;</span>)      <span class="ruby-comment"># Sets cell A1 to string &quot;A1&quot;</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">add_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>, <span class="ruby-string">&#39;&#39;</span>, <span class="ruby-string">&#39;A1&#39;</span>)  <span class="ruby-comment"># Sets formula in the cell B1 to &#39;=A1&#39;</span>
</pre>

<h4 id="label-Changing+Cells">Changing Cells<span><a href="#label-Changing+Cells">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_contents</span>(<span class="ruby-string">&quot;&quot;</span>, <span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">formula</span>) <span class="ruby-comment"># Sets value of cell A1 to empty string, preserves formula</span>

<span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">add_shared_string</span>(<span class="ruby-string">&#39;some text&#39;</span>) <span class="ruby-comment"># Creates a new Shared String and adds it to the cell.</span>
                                               <span class="ruby-comment"># Later, the same Shared String can be added to other cells.</span>
</pre>

<h4 id="label-Changing+Fonts">Changing Fonts<span><a href="#label-Changing+Fonts">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_font_bold</span>(<span class="ruby-keyword">true</span>) <span class="ruby-comment"># Makes A1 bold</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_italics</span>(<span class="ruby-value">0</span>,<span class="ruby-keyword">true</span>)              <span class="ruby-comment"># Makes first row italicized</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_font_name</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;Courier&#39;</span>)   <span class="ruby-comment"># Makes first column have font Courier</span>
</pre>

<h4 id="label-Changing+Fills+++++">Changing Fills     <span><a href="#label-Changing+Fills+++++">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_fill</span>(<span class="ruby-string">&#39;0ba53d&#39;</span>)  <span class="ruby-comment"># Sets A1 to have fill #0ba53d</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_fill</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;0ba53d&#39;</span>)            <span class="ruby-comment"># Sets first row to have fill #0ba53d</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_fill</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;0ba53d&#39;</span>)         <span class="ruby-comment"># Sets first column to have fill #0ba53d</span>
</pre>

<h4 id="label-Changing+Borders">Changing Borders<span><a href="#label-Changing+Borders">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-comment"># Possible weights: hairline, thin, medium, thick</span>
<span class="ruby-comment"># Possible &quot;directions&quot;: top, bottom, left, right, diagonal</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_border</span>(<span class="ruby-value">:top</span>, <span class="ruby-string">&#39;thin&#39;</span>)  <span class="ruby-comment"># Sets A1 to have a top, thin border</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_border</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:left</span>, <span class="ruby-string">&#39;hairline&#39;</span>)       <span class="ruby-comment"># Sets first row to have a left, hairline border</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_border</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:diagonal</span>, <span class="ruby-string">&#39;medium&#39;</span>)  <span class="ruby-comment"># Sets first column to have diagonal, medium border</span>

<span class="ruby-comment"># Set the border style first so there&#39;s something to color.</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_border_color</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:top</span>, <span class="ruby-string">&#39;0ba53d&#39;</span>)    <span class="ruby-comment"># Sets first row to have a green top border</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_border_color</span>(<span class="ruby-value">0</span>, <span class="ruby-value">:top</span>, <span class="ruby-string">&#39;0ba53d&#39;</span>) <span class="ruby-comment"># Sets first column to have a green top border</span>
</pre>

<h4 id="label-Changing+Alignment">Changing Alignment<span><a href="#label-Changing+Alignment">&para;</a> <a href="#top">&uarr;</a></span></h4>

<h5 id="label-Horizontal">Horizontal<span><a href="#label-Horizontal">&para;</a> <a href="#top">&uarr;</a></span></h5>

<pre class="ruby"><span class="ruby-comment"># Possible alignments: center, distributed, justify, left, right</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_horizontal_alignment</span>(<span class="ruby-string">&#39;center&#39;</span>) <span class="ruby-comment"># Sets A1 to be centered</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_horizontal_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;justify&#39;</span>)          <span class="ruby-comment"># Sets first row to be justified</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_horizontal_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;right&#39;</span>)         <span class="ruby-comment"># Sets first column to be right-aligned</span>
</pre>

<h5 id="label-Vertical">Vertical<span><a href="#label-Vertical">&para;</a> <a href="#top">&uarr;</a></span></h5>

<pre class="ruby"><span class="ruby-comment"># Possible alignments: bottom, center, distributed, top</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_vertical_alignment</span>(<span class="ruby-string">&#39;bottom&#39;</span>)  <span class="ruby-comment"># Sets A1 to be bottom aligned</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_vertical_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;distributed&#39;</span>)       <span class="ruby-comment"># Sets first row to be distributed vertically</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_vertical_alignment</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;top&#39;</span>)            <span class="ruby-comment"># Sets first column to be top aligned</span>
</pre>

<h5 id="label-Rotation">Rotation<span><a href="#label-Rotation">&para;</a> <a href="#top">&uarr;</a></span></h5>

<pre class="ruby"><span class="ruby-comment"># Possible values:</span>
<span class="ruby-comment"># * 0-90 - degrees counterclockwise, around the bottom LEFT corner of the cell;</span>
<span class="ruby-comment"># * 91-179 - degrees clockwise, around the bottom RIGHT corner of the cell;</span>
<span class="ruby-comment"># * 180-254 - degrees clockwise, around the bottom LEFT corner of the cell, text becomes progressively invisible</span>
<span class="ruby-comment"># * 255 - text is in normal rotation but displayed vertically (one letter under another), line feed starts new line to the right of the previous.</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">sheet_data</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>].<span class="ruby-identifier">change_text_rotation</span>(<span class="ruby-value">90</span>)  <span class="ruby-comment"># Sets A1 to be rotated by 90 degrees</span>
</pre>

<h4 id="label-Changing+Row+Height">Changing Row Height<span><a href="#label-Changing+Row+Height">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_row_height</span>(<span class="ruby-value">0</span>, <span class="ruby-value">30</span>)  <span class="ruby-comment"># Sets first row height to 30</span>
</pre>

<h4 id="label-Changing+Column+Width">Changing Column Width<span><a href="#label-Changing+Column+Width">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">change_column_width</span>(<span class="ruby-value">0</span>, <span class="ruby-value">30</span>)  <span class="ruby-comment"># Sets first column width to 30</span>
</pre>

<h4 id="label-Merging+Cells">Merging Cells<span><a href="#label-Merging+Cells">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">merge_cells</span>(<span class="ruby-value">0</span>, <span class="ruby-value">1</span>, <span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-comment"># Merges B1:D3</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">merge_cells</span>(<span class="ruby-string">&#39;A2:C4&#39;</span>)     <span class="ruby-comment"># Merges A2:C4</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">merge_cells</span>(<span class="ruby-value">row_from:</span> <span class="ruby-value">0</span>, <span class="ruby-value">row_to:</span> <span class="ruby-value">1</span>, <span class="ruby-value">col_from:</span> <span class="ruby-value">2</span>, <span class="ruby-value">col_to:</span> <span class="ruby-value">3</span>) <span class="ruby-comment"># Merges C1:D2</span>
</pre>

<h4 id="label-Insert+Row">Insert Row<span><a href="#label-Insert+Row">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This method will insert a row at specified index, pushing all rows below it down. It also copies styles from row above.</p>

<p>WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted rows</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">insert_row</span>(<span class="ruby-value">1</span>)
</pre>

<h4 id="label-Insert+Column">Insert Column<span><a href="#label-Insert+Column">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This method will insert a column at specified index, pushing all columns to the right of it one to the right. It also copies styles from column to the left</p>

<p>WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted columns</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">insert_column</span>(<span class="ruby-value">1</span>)
</pre>

<h4 id="label-Delete+Row">Delete Row<span><a href="#label-Delete+Row">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This method will delete a row at specified index, pushing all rows below it up.</p>

<p>WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted rows</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">delete_row</span>(<span class="ruby-value">1</span>)
</pre>

<h4 id="label-Delete+Column">Delete Column<span><a href="#label-Delete+Column">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This method will delete a column at specified index, pushing all columns to the right of it left.</p>

<p>WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted columns</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">delete_column</span>(<span class="ruby-value">1</span>)
</pre>

<h4 id="label-Insert+Cell">Insert Cell<span><a href="#label-Insert+Cell">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This method will insert a cell at specified position. It takes a :right or :down option, to shift cells either left or down upon inserting (nil means replacing the cell)</p>

<p>WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted cells</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">insert_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-string">&quot;blah&quot;</span>, <span class="ruby-identifier">formula</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-value">:right</span>)  <span class="ruby-comment"># Inserts cell at A1, shifts cells in first row right</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">insert_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-string">&quot;blah&quot;</span>, <span class="ruby-identifier">formula</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-value">:down</span>)   <span class="ruby-comment"># Inserts cell at A1, shifts cells in first column down</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">insert_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-string">&quot;blah&quot;</span>)                         <span class="ruby-comment"># Inserts cell at A1, shifts nothing</span>
</pre>

<h4 id="label-Delete+Cell">Delete Cell<span><a href="#label-Delete+Cell">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>This method will delete a cell at specified position. It takes a :left or :up option, to shift cells either up or left upon deletion (nil means simply deleting the cell contents)</p>

<p>WARNING: Use of this method WILL break formulas referencing cells which have been moved, as the formulas do not adapt to the shifted cells</p>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">delete_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">:left</span>)  <span class="ruby-comment"># Deletes A1, shifts contents of first row left</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">delete_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">:up</span>)    <span class="ruby-comment"># Deletes A1, shifts contents of first column up</span>
<span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">delete_cell</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>)         <span class="ruby-comment"># Deletes A1, does not shift cells</span>
</pre>

<h4 id="label-Modifying+Cell+Format">Modifying Cell Format<span><a href="#label-Modifying+Cell+Format">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">cell</span> = <span class="ruby-identifier">worksheet</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>]
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">set_number_format</span> <span class="ruby-string">&#39;0.0000%&#39;</span>    <span class="ruby-comment"># For formats, see https://support.office.com/en-us/article/5026bbd6-04bc-48cd-bf33-80f18b4eae68</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">change_text_wrap</span>(<span class="ruby-keyword">true</span>)         <span class="ruby-comment"># Makes the text in the cell to wrap.</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">change_shrink_to_fit</span>(<span class="ruby-keyword">true</span>)     <span class="ruby-comment"># Makes the text in the cell to shrink to fit.</span>
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">change_text_indent</span>(<span class="ruby-value">1</span>)          <span class="ruby-comment"># Indents the text in the cell by 1 level</span>
</pre>

<h4 id="label-Add+hyperlink+to+a+Cell">Add hyperlink to a Cell<span><a href="#label-Add+hyperlink+to+a+Cell">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">cell</span>.<span class="ruby-identifier">add_hyperlink</span>(<span class="ruby-string">&#39;http://example.com&#39;</span>)
<span class="ruby-identifier">cell</span>.<span class="ruby-identifier">add_hyperlink</span>(<span class="ruby-string">&#39;http://example.com&#39;</span>, <span class="ruby-string">&#39;Some tooltip text&#39;</span>)
</pre>

<h2 id="label-I-2FO">I/O<span><a href="#label-I-2FO">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>By default, the gem operates with files on the local filesystem:</p>

<pre class="ruby"><span class="ruby-identifier">workbook</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;path/to/Excel/file.xlsx&quot;</span>)
<span class="ruby-identifier">workbook</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&quot;path/to/desired/Excel/file.xlsx&quot;</span>)
</pre>

<p>It can also operate on <code>StringIO</code> objects, thus eliminating the need to save the <code>xlsx</code> file to disk. This capability comes in handy for web servers.</p>

<pre class="ruby"><span class="ruby-identifier">workbook</span> = <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Parser</span>.<span class="ruby-identifier">parse_buffer</span>(<span class="ruby-identifier">buffer</span>)
<span class="ruby-identifier">workbook</span>.<span class="ruby-identifier">stream</span>
</pre>

<h2 id="label-Miscellaneous">Miscellaneous<span><a href="#label-Miscellaneous">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Reference</span>.<span class="ruby-identifier">ind2ref</span>(<span class="ruby-value">0</span>,<span class="ruby-value">0</span>) <span class="ruby-operator">==</span> <span class="ruby-string">&#39;A1&#39;</span>    <span class="ruby-comment"># Converts row and column index to Excel-style cell reference</span>
<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Reference</span>.<span class="ruby-identifier">ref2ind</span>(<span class="ruby-string">&#39;A1&#39;</span>) <span class="ruby-operator">==</span> [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>] <span class="ruby-comment"># Converts Excel-style cell reference to row and column index</span>
</pre>

<h3 id="label-Suppress+warnings+about+malformed+input+files">Suppress warnings about malformed input files<span><a href="#label-Suppress+warnings+about+malformed+input+files">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-constant">RubyXL</span>.<span class="ruby-identifier">class_variable_set</span>(<span class="ruby-value">:@@suppress_warnings</span>, <span class="ruby-keyword">true</span>)
</pre>

<h2 id="label-Data+validation+-28colloquially+referred+to+as+-22dropdown+list-22-29">Data validation (colloquially referred to as “dropdown list”)<span><a href="#label-Data+validation+-28colloquially+referred+to+as+-22dropdown+list-22-29">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">worksheet</span>.<span class="ruby-identifier">add_validation_list</span>(<span class="ruby-string">&quot;A1&quot;</span>, [ <span class="ruby-string">&quot;value1&quot;</span>, <span class="ruby-string">&quot;value2&quot;</span> ])
</pre>

<h2 id="label-For+more+information">For more information<span><a href="#label-For+more+information">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Take a look at the files in spec/lib/ for rspecs on most methods</p>

<h2 id="label-Contributing+to+rubyXL">Contributing to rubyXL<span><a href="#label-Contributing+to+rubyXL">&para;</a> <a href="#top">&uarr;</a></span></h2>
<ul><li>
<p>Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet</p>
</li><li>
<p>Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it</p>
</li><li>
<p>Fork the project</p>
</li><li>
<p>Start a feature/bugfix branch</p>
</li><li>
<p>Commit and push until you are happy with your contribution</p>
</li><li>
<p>Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.</p>
</li><li>
<p>Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.</p>
</li></ul>

<h2 id="label-Copyright">Copyright<span><a href="#label-Copyright">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Copyright © 2011 Vivek Bhagwat, 2013-2022 Wesha. See LICENSE.txt for further details.</p>

</main>
</body>

